﻿namespace Text2Rss.Database.Migrations
{
	#region Using Directives
	using System.Data;
	using ECM7.Migrator.Framework;
	#endregion

	/// <summary>
	/// Create table for Feeds
	/// </summary>
	[Migration(3)]
	public class Migration003_Feed : Migration
	{
		public override void Apply()
		{
			Database.AddTable(
				"Feed",
				new Column("Id", DbType.Guid, ColumnProperty.PrimaryKey),
				new Column("Version", DbType.Int32, ColumnProperty.NotNull),
				new Column("OwnerId", DbType.String.WithSize(100), ColumnProperty.NotNull),
				new Column("SourceFileId", DbType.Int32, ColumnProperty.NotNull),
				new Column("PublishInterval", DbType.Int32, ColumnProperty.NotNull),
				new Column("PostSize", DbType.Int32, ColumnProperty.NotNull),
				new Column("CurrentPosition", DbType.Int64, ColumnProperty.NotNull));

			Database.AddForeignKey("FK_Feed_User", "Feed", "OwnerId", "Users", "Email");

			Database.AddForeignKey("FK_Feed_SourceFile", "Feed", "SourceFileId", "SourceFile", "Id");
		}

		public override void Revert()
		{
			Database.RemoveTable("Feed");
		}
	}
}
